package com.cykj.controller;

import com.cykj.dto.ResponseDTO;
import com.cykj.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @BelongsProject: jd-project
 * @BelongsPackage: com.cykj.controller
 * @Author: 小林
 * @CreateTime: 2025-02-24 16:07
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
        private RedisTemplate<String,Object> redisTemplate;

    @RequestMapping("redis")
    public void redis(){
        redisTemplate.opsForValue().set("name","1111");
        System.out.println(redisTemplate.opsForValue().get("name"));
    }
    @PostMapping("login")
    public ResponseDTO login(@RequestParam("acc") String acc,@RequestParam("pwd") String pwd){
       return userService.login(acc,pwd);
    }
    @Autowired
    private RestTemplate restTemplate;
    //写一个接口去调用商品微服务
    @RequestMapping("restTemplateTestByUser")
    public void restTemplateTestByUser(){
//         String forObject = restTemplate.getForObject("http://127.0.0.1:8083/goods/resTemplateTest", String.class);
        //商品
//         String forObject = restTemplate.getForObject("http://jd-goods/goods/resTemplateTest", String.class);
        //订单
         String forObject = restTemplate.getForObject("http://jd-order/order/resTemplateTest", String.class);

        System.out.println(forObject);
    }

    @PostMapping("test")
    public String test(){
        return "test";
    }
}

